package com.example.baserecyclerviewadapterdemo.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.example.baserecyclerviewadapterdemo.R;
import com.example.baserecyclerviewadapterdemo.adapter.SectionQuickAdapter;
import com.example.baserecyclerviewadapterdemo.base.BaseActivity;
import com.example.baserecyclerviewadapterdemo.data.DataServer;
import com.example.baserecyclerviewadapterdemo.decoration.GridSectionAverageGapItemDecoration;
import com.example.baserecyclerviewadapterdemo.entity.MySection;

import java.util.List;

public class QuickSectionActivity extends BaseActivity {
    private RecyclerView recyclerView;
    private List<MySection> mySections;
    private SectionQuickAdapter adapter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_multiple_item_use);
        getParentToolbar().setTitle("Quick Section Use");
        getParentToolbar().setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        recyclerView = findViewById(R.id.rv_list);
        recyclerView.setLayoutManager(new GridLayoutManager(this,3));
        recyclerView.addItemDecoration(new GridSectionAverageGapItemDecoration(10,10,25,15));
        mySections = DataServer.getSectionData();
        adapter = new SectionQuickAdapter(R.layout.def_section_head,R.layout.item_section_content,DataServer.getSectionData());
        recyclerView.setAdapter(adapter);
        adapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
                switch (view.getId()) {
                    case R.id.more:
                        Toast.makeText(QuickSectionActivity.this,"点击了:" + position,Toast.LENGTH_LONG).show();
                    break;
                }
            }
        });
    }
}
